﻿
@{
    ViewBag.Title = "Custom";
    Layout = "~/Views/Shared/_LayoutForEUI.cshtml";
}
<table id="StatArchive_Custom_grid" class="easyui-datagrid" style="width:100%;" title="档案分类统计" data-options="
       rownumbers:true,
       singleSelect:true,
       autoRowHeight:false,
       pagination:false,
       fitColumns:true,
       fit:false,
       striped:true,
       checkOnSelect:false,
       selectOnCheck:false,
       toolbar:'#StatArchive_Custom_tb',
       collapsible:false,
       pageSize: @SGArchiveSystem7x.Models.CCommonsModels.PageSize,
       pageList:[10,15,20]">
    <thead frozen="true">
       </thead>
</table>
<div id="StatArchive_Custom_tb" style="padding:5px 10px;">
    <select class="easyui-combobox" labelwidth="60px" style="width:220px" id="StatArchive_Custom_cmbArciveTree" label="档案类型" labelalign="right" editable="false" panelHeight="auto">
        @{
            var listArchiveType = ViewBag.Items as List<SGArchiveSystem7x.Models.CComboboxModel>;
            foreach (var item in listArchiveType)
            {
                <option value="@item.ID">@item.Text</option>
            }
        }
    </select>
    <select class="easyui-combobox" labelwidth="90px" style="width:220px" id="StatArchive_Custom_cmbS1" label="统计字段(Y轴)" labelalign="right" editable="false" panelHeight="auto"></select>
    <select class="easyui-combobox" labelwidth="90px" style="width:220px" id="StatArchive_Custom_cmbS2" label="统计字段(X轴)" editable="false" panelHeight="auto"></select>
    <a href="javascript:void(0);" class="easyui-linkbutton button-blue" onclick="startStat()" style="width:110px;height:30px;">统计</a>
    <a href="javascript:void(0);" class="easyui-linkbutton button-blue" onclick="startXls()" style="width:110px;height:30px;">导出xls</a>
</div>
<iframe src="" id="StatArchive_Custom_frm" width="100%" height="100%" frameborder="0" scrolling="auto"></iframe>
<script>
    $(document).ready(function () {
         $("#StatArchive_Custom_cmbArciveTree").combobox({
             onChange: function (n, o) {
                 fieldsChange(n,o);
             }
        });

        fieldsChange($('#StatArchive_Custom_cmbArciveTree').combobox('getValue'));
    });

    function fieldsChange(n,o) {
        $("#StatArchive_Custom_cmbS1").combobox({
            url: '/StatArchive/CustomBuildComboboxFields?pid=' + n,
            valueField: 'Value',
            textField: 'Text'
        });

        $("#StatArchive_Custom_cmbS2").combobox({
            url: '/StatArchive/CustomBuildComboboxFields?pid=' + n,
            valueField: 'Value',
            textField: 'Text'
        });
    }

    function startStat() {
        var f1 = $('#StatArchive_Custom_cmbS1').combobox('getValue');
        var f2 = $('#StatArchive_Custom_cmbS2').combobox('getValue');
        var arid = $('#StatArchive_Custom_cmbArciveTree').combobox('getValue');

        if (f1 == '' || f2 == '')
            $.messager.alert('提示', '统计字段不能为空!', 'error');
        else if (f1 == f2)
            $.messager.alert('提示', '两个统计字段不能相同!', 'error');
        else {
            document.getElementById('StatArchive_Custom_frm').src = "/StatArchive/StartStat?arid=" +  arid + '&f1=' + f1 + '&f2=' + f2;
            //$.ajax({
            //    url: '/StatArchive/StartStat?arid=' + arid + '&f1=' + f1 + '&f2=' + f2,
            //    type: 'post',
            //    asyns: false,
            //    dataType: 'html',
            //    cache: false,
            //    success: function (data) {
            //        alert(data);
            //    }
            //})
        }
    }

    function startXls() {
        if (document.getElementById('StatArchive_Custom_frm').src == '')
            $.messager.alert('提示', '请先统计出数据才能导出xls表', 'error');
        else {
            $.ajax({
                url: '/StatArchive/StartStatXls',
                type: 'post',
                asyns: false,
                dataType: 'text',
                cache: false,
                success: function (data) {
                    if (data == '-1')
                        $.messager.alert('提示', '未统计出数据，不能导出xls表', 'error');
                    else {
                        window.open(data);
                    }
                }
            })
        }
    }
</script>

